<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php 
	printf($this->Html->charset() . PHP_EOL);
	printf('<title>%s</title>'  . PHP_EOL,
		strip_tags(
			implode(' :: ', array_merge(
				array(__d('lil', 'LilIntranet')),
				Set::filter(array($title_for_layout))
			))
		)
	);
	printf($this->Html->css('/lil/css/layout') . PHP_EOL);
	printf($this->Html->css('/lil/css/Aristo/jquery-ui-1.8.7.custom') . PHP_EOL);
	printf($this->Html->css('/lil/css/lil_print', null, array('media' => 'print')) . PHP_EOL);
	printf($this->Html->css('/lil/css/lil_mobile', null, array('media' => 'only screen and (max-device-width: 480px)')) . PHP_EOL);
	
	printf($this->Html->script('/lil/js/jquery-1.7.1.min') . PHP_EOL);
	printf($this->Html->script('/lil/js/jquery-ui-1.8.16.custom.min') . PHP_EOL);
	printf($this->Html->script('/lil/js/jquery.dataTables.min') . PHP_EOL);
	printf($this->Html->script('/lil/js/jquery.mousewheel.min') . PHP_EOL);
	printf($this->Html->script('/lil/js/lil_popups') . PHP_EOL);
	printf($this->Html->script('/lil/js/lil_float') . PHP_EOL);
	
	
	printf($scripts_for_layout . PHP_EOL);
?>
	<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
	<!-- enable full-screen mode (only when launched from home screen) -->
	<meta name="apple-mobile-web-app-capable" content="yes" />

	<!-- controls the appearance of the status bar in full-screen mode -->
	<meta name="apple-mobile-web-app-status-bar-style" content="black" />

</head>
<body>
	<div id="container">
		<div id="header">
		<?php
			printf('<div id="header-logo">%s</div>' . PHP_EOL,
				$this->Html->link(
					$this->Html->image('/lil/img/logo.gif'),
					'/admin',
					array('escape' => false)
				)
			);
			
			printf('<h1>%s</h1>' . PHP_EOL,
				Configure::read('Lil.noAreas') === true ? __d('lil', 'Welcome') : 
				(empty($admin_area) ?
					$this->Html->link(
						__d('lil', '-- no area selected --'),
						array(
							'admin'      => true,
							'plugin'     => 'lil',
							'controller' => 'areas',
							'action'     => 'list',
						),
						array(
							'class' => 'no-area'
						)
					)
				:
					$this->Html->link(
						$admin_area['Area']['name'],
						array(
							'admin'      => true,
							'plugin'     => 'lil',
							'controller' => 'areas',
							'action'     => 'dashboard',
							'area'       => $admin_area['Area'][Configure::read('Lil.areaSlugField')],
						)
					)
				)
			);
			
			if ($user = $this->Lil->currentUser->get('id')) {
				printf('<div id="header-user">%1$s</div>',
					$this->Html->link(
						$this->Lil->currentUser->get(Configure::read('Lil.userDisplayField')),
						'#',
						array(
							'class' => 'popup_link',
							'id'    => 'popup_link_user'
						)
					)
				);
				printf('<div class="popup popup_link_user"><ul class="menu">');
				if (Configure::read('Lil.noAreas') !== true) {
					printf('<li>%s</li>', $this->Html->link(__d('lil', 'Change Area'), array(
						'admin' => true,
						'plugin' => 'lil',
						'controller' => 'areas',
						'action' => 'list'
					)));
				}
				printf('<li>%s</li>', $this->Html->link(__d('lil', 'Settings'), array(
					'admin' => true,
					'plugin' => 'lil',
					'controller' => 'users',
					'action' => 'properties'
				)));
				printf('<li><hr /></li>');
				printf('<li>%s</li>', $this->Html->link(__d('lil', 'Logout'), array(
					'admin' => true,
					'plugin' => 'lil',
					'controller' => 'users',
					'action' => 'logout'
				)));
				printf('</ul></div>');
			}
		?>
		</div>
		<div id="main-menu">
			<h1>&nbsp;</h1>
			<?php
				if (!isset($main_menu)) $main_menu = array();
				
				if (!empty($main_menu)) {
					App::uses('LilPluginRegistry', 'Lil.Lil'); $registry = LilPluginRegistry::getInstance();
					$main_menu = $registry->callPluginHandlers($this, 'admin_main_menu', $main_menu);
					$this->Lil->menu($main_menu);
				}
				
			?>
		</div>
		<div id="content">
			<div id="sidebar">
			<?php echo $this->element('admin_sidebar'); ?>
			</div>
			<div id="main">
			<?php
				if ($this->Session->check('Message.flash')) echo $this->Session->flash();
				if ($this->Session->check('Message.auth')) echo $this->Session->flash('auth');
		
				if (!isset($head_for_layout) || ($head_for_layout !== false)) {
					if (!empty($head_for_layout)) {
						printf($this->element($head_for_layout));
					} else {
						printf('<div class="head"><h1>%s</h1></div>', $title_for_layout);
					}
				}
				$this->Lil->outputPopups();
				
				echo $content_for_layout;
				
				printf($this->Html->script('/lil/js/lil_datatables') . PHP_EOL);
			?>
			</div>
			<div style="clear: both;" />
		</div>
	</div>
	<script type="text/javascript">
		$(document).ready(function() {
			$.ajaxSetup ({ cache: false });
			$('button, input:submit' ).button();
				
			<?php
				echo $this->Lil->jsReadyOut();
			?>
		});
		
	</script>
	
	<iframe id="lil_post_iframe" name="lil_post_iframe" src="about:blank" style="display:none;" />
	<?php echo $this->element('sql_dump'); ?>
</body>
</html>